import {
  uploadToQiniu
} from "../../utils/uploadToQiniu"
Page({

  data: {
    problem: [{
      title: '功能异常',
      type: 1
    }, {
      title: '缺陷漏洞',
      type: 2
    }, {
      title: '产品建议',
      type: 3
    }, {
      title: '用户体验',
      type: 4
    }, {
      title: '视觉体验',
      type: 5
    }, {
      title: '其他',
      type: 6
    }, {
      title: '退款申请',
      type: 7
    }],
    problem_curr: -1,
    wt_type: '',
    msg: '',
    img: [],
  },

  onLoad(options) {
    if (options.problem_curr) {
      this.setData({
        problem_curr: options.problem_curr
      })
    }
  },

  change_problem_curr(e) {
    this.setData({
      problem_curr: e.currentTarget.dataset.type,
      wt_type: e.currentTarget.dataset.title,
    })
  },

  change_msg(e) {
    this.setData({
      msg: e.detail.value
    })
  },

  onChangeTap(e) {
    let url = e.detail.current[0];
    getApp().globalData.uploads(url).then(res => {
      console.log(res)
    })
  },


  bottomTap() {
    if (!this.data.wt_type) {
      getApp().showToast('请选择问题类型')
      return
    }
    if (!this.data.msg) {
      getApp().showToast('请填写问题反馈')
      return
    }
    const image_icker = this.selectComponent('#image_picker');
    let img_arr = image_icker.linGetValue()
    let num = 0;
    let img = []
    if (img_arr.length == 0) {
      this.jb()
    } else {
      img_arr.forEach((v, i) => {
        uploadToQiniu(v).then((res) => {
          img.push(res)
          num = num + 1
          if (num == img_arr.length) {
            this.setData({
              img
            })
            this.jb()
          }
        })
      })
    }
  },

  jb() {
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/jb', {
      type: 2,
      msg: this.data.msg,
      wt_type: this.data.wt_type,
      img: this.data.img.join(',')
    }).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        wx.navigateBack()
      })
    })
  },

})